﻿@model TopicModel
@Html.ValidationSummary(false)

<script type="text/javascript">
    $(document).ready(function () {
        $("#@Html.FieldIdFor(model => model.IsPasswordProtected)").click(togglePassword);
        togglePassword();
    });
    function togglePassword() {
        if ($('#@Html.FieldIdFor(model => model.IsPasswordProtected)').is(':checked')) {
            $('#pnlPasswordEnabled').show();
        }
        else {
            $('#pnlPasswordEnabled').hide();
        }
    }       
</script>
@Html.HiddenFor(model => model.Id)

<div id="topic-edit">
    <ul>
        <li @Html.RenderSelectedTabIndex(0, GetSelectedTabIndex())>
            @T("Admin.ContentManagement.Topics.Info")
        </li>
        <li @Html.RenderSelectedTabIndex(1, GetSelectedTabIndex())>
            @T("Admin.Common.SEO")
        </li>
        <li @Html.RenderSelectedTabIndex(2, GetSelectedTabIndex())>
            @T("Admin.ContentManagement.Topics.Stores")
        </li>
    </ul>
    <div>
        @TabInfo()
    </div>
    <div>
        @TabSeo()
    </div>
    <div>
        @TabStores()
    </div>
</div>
<script>
    $(document).ready(function () {
        $("#topic-edit").kendoTabStrip({
            animation: {
                open: {
                    effects: "fadeIn"
                }
            },
            select: tabstrip_on_tab_select
        });
    });
</script>

@{
    //custom tabs
    var eventMessage = new AdminTabStripCreated(this.Html, "topic-edit");
    EngineContext.Current.Resolve<IEventPublisher>().Publish(eventMessage);
    foreach (var eventBlock in eventMessage.BlocksToRender)
    {
        @eventBlock
    }
}

@*save selected tab index*@
<input type="hidden" id="selected-tab-index" name="selected-tab-index" value="@(GetSelectedTabIndex())">

@helper TabInfo()
    { 
    <table class="adminContent">
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.SystemName):
            </td>
            <td class="adminData">
                @Html.EditorFor(model => model.SystemName)
                @Html.ValidationMessageFor(model => model.SystemName)
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.IsPasswordProtected):
            </td>
            <td class="adminData">
                @Html.EditorFor(model => model.IsPasswordProtected)
                @Html.ValidationMessageFor(model => model.IsPasswordProtected)
            </td>
        </tr>
        <tr id="pnlPasswordEnabled">
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.Password):
            </td>
            <td class="adminData">
                @Html.EditorFor(model => model.Password)
                @Html.ValidationMessageFor(model => model.Password)
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.IncludeInSitemap):
            </td>
            <td class="adminData">
                @Html.EditorFor(x => x.IncludeInSitemap)
                @Html.ValidationMessageFor(model => model.IncludeInSitemap)
            </td>
        </tr>
        @if (Model.Id > 0)
        {
            <tr>
                <td class="adminTitle">
                    @Html.NopLabelFor(model => model.Url):
                </td>
                <td class="adminData">
                    <a href="@Model.Url">@Model.Url</a>
                </td>
            </tr>
        }
    </table>
    @(Html.LocalizedEditor<TopicModel, TopicLocalizedModel>("topic-info-localized",
                @<table class="adminContent">
                    <tr>
                        <td class="adminTitle">
                            @Html.NopLabelFor(model => model.Locales[item].Title):
                        </td>
                        <td class="adminData">
                            @Html.EditorFor(model => model.Locales[item].Title)
                            @Html.ValidationMessageFor(model => model.Locales[item].Title)
                        </td>
                    </tr>
                    <tr>
                        <td class="adminTitle">
                            @Html.NopLabelFor(model => model.Locales[item].Body):
                        </td>
                        <td class="adminData">
                            @Html.EditorFor(model => model.Locales[item].Body, "RichEditor")
                            @Html.ValidationMessageFor(model => model.Locales[item].Body)
                        </td>
                    </tr>
                    <tr>
                        <td colspan="2">
                            @Html.HiddenFor(model => model.Locales[item].LanguageId)
                        </td>
                    </tr>
                </table>
                ,
                @<table class="adminContent">
                    <tr>
                        <td class="adminTitle">
                            @Html.NopLabelFor(model => model.Title):
                        </td>
                        <td class="adminData">
                            @Html.EditorFor(model => model.Title)
                            @Html.ValidationMessageFor(model => model.Title)
                        </td>
                    </tr>
                    <tr>
                        <td class="adminTitle">
                            @Html.NopLabelFor(model => model.Body):
                        </td>
                        <td class="adminData">
                            @Html.EditorFor(x => x.Body, "RichEditor")
                            @Html.ValidationMessageFor(model => model.Body)
                        </td>
                    </tr>
                </table>
            ))
}
@helper TabSeo()
    {
    @(Html.LocalizedEditor<TopicModel, TopicLocalizedModel>("topic-seo-localized",
               @<table class="adminContent">
                   <tr>
                       <td class="adminTitle">
                           @Html.NopLabelFor(model => model.Locales[item].MetaKeywords):
                       </td>
                       <td class="adminData">
                           @Html.EditorFor(model => model.Locales[item].MetaKeywords)
                           @Html.ValidationMessageFor(model => model.Locales[item].MetaKeywords)
                       </td>
                   </tr>
                   <tr>
                       <td class="adminTitle">
                           @Html.NopLabelFor(model => model.Locales[item].MetaDescription):
                       </td>
                       <td class="adminData">
                           @Html.TextAreaFor(model => model.Locales[item].MetaDescription)
                           @Html.ValidationMessageFor(model => model.Locales[item].MetaDescription)
                       </td>
                   </tr>
                   <tr>
                       <td class="adminTitle">
                           @Html.NopLabelFor(model => model.Locales[item].MetaTitle):
                       </td>
                       <td class="adminData">
                           @Html.EditorFor(model => model.Locales[item].MetaTitle)
                           @Html.ValidationMessageFor(model => model.Locales[item].MetaTitle)
                       </td>
                   </tr>
                <tr>
                    <td class="adminTitle">
                        @Html.NopLabelFor(model => model.Locales[item].SeName):
                    </td>
                    <td class="adminData">
                        @Html.EditorFor(model => model.Locales[item].SeName)
                        @Html.ValidationMessageFor(model => model.Locales[item].SeName)
                    </td>
                </tr>
                   <tr>
                       <td colspan="2">
                           @Html.HiddenFor(model => model.Locales[item].LanguageId)
                       </td>
                   </tr>
               </table>
               ,
               @<table class="adminContent">
                   <tr>
                       <td class="adminTitle">
                           @Html.NopLabelFor(model => model.MetaKeywords):
                       </td>
                       <td class="adminData">
                           @Html.EditorFor(x => x.MetaKeywords)
                           @Html.ValidationMessageFor(model => model.MetaKeywords)
                       </td>
                   </tr>
                   <tr>
                       <td class="adminTitle">
                           @Html.NopLabelFor(model => model.MetaDescription):
                       </td>
                       <td class="adminData">
                           @Html.TextAreaFor(x => x.MetaDescription)
                           @Html.ValidationMessageFor(model => model.MetaDescription)
                       </td>
                   </tr>
                   <tr>
                       <td class="adminTitle">
                           @Html.NopLabelFor(model => model.MetaTitle):
                       </td>
                       <td class="adminData">
                           @Html.EditorFor(x => x.MetaTitle)
                           @Html.ValidationMessageFor(model => model.MetaTitle)
                       </td>
                   </tr>
                    <tr>
                        <td class="adminTitle">
                            @Html.NopLabelFor(model => model.SeName):
                        </td>
                        <td class="adminData">
                            @Html.EditorFor(x => x.SeName)
                            @Html.ValidationMessageFor(model => model.SeName)
                        </td>
                    </tr>
               </table>))
}

@helper TabStores()
{
    <script type="text/javascript">
        $(document).ready(function () {

            $("#@Html.FieldIdFor(model => model.LimitedToStores)").click(toggleStoreMapping);

            toggleStoreMapping();
        });


        function toggleStoreMapping() {
            if ($('#@Html.FieldIdFor(model => model.LimitedToStores)').is(':checked')) {
                $('#pnl-available-stores').show();
            }
            else {
                $('#pnl-available-stores').hide();
            }
        }

    </script>
    <table class="adminContent">
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.LimitedToStores):
            </td>
            <td class="adminData">
                @Html.EditorFor(model => model.LimitedToStores)
                @Html.ValidationMessageFor(model => model.LimitedToStores)
            </td>
        </tr>
        <tr id="pnl-available-stores">
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.AvailableStores):
            </td>
            <td class="adminData">
                @if (Model.AvailableStores != null && Model.AvailableStores.Count > 0)
                {
                    foreach (var store in Model.AvailableStores)
                    {
                    <div>
                        <input type="checkbox" name="SelectedStoreIds" value="@store.Id" checked="@(Model.SelectedStoreIds != null && Model.SelectedStoreIds.Contains(store.Id))" />@store.Name
                    </div>
                    }
                }
                else
                {
                    <div>No stores defined</div>
                }</td>
        </tr>
    </table>
}

